#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
        int n;
        cin >> n;
        
        vector<vector<int>> gh(n, vector<int>(n, 0));
        vector<int> dp(n, 0);

        for(int i = 0; i < n; i++){
                for(int j = 0; j<n; j++){
                        cin>>gh[i][j];
                }
        }

        dp[0] = gh[0][0];
        for(int i = 1; i < n; i++){
                dp[i] = dp[i-1] + gh[0][i];
        }

        for(int i = 1; i < n; i++){
                dp[0] += gh[i][0];
                for(int j = 1; j < n; j++){
                        dp[j] = min(dp[j], dp[j-1]) + gh[i][j];
                }
        }

        cout<<dp.back()<<endl;
        return 0;
}